#pragma once
#include <iostream>
#include <unordered_map>
#include <string>
#include <vector>
#include <fstream>

const std::string mydictpath = "./recource/dict.txt";

class TranslateWord
{
public:
    TranslateWord(const std::string& dict_path = mydictpath)
    :_dict_path(dict_path)
    {
        LodeLines();
        LodeDict();
    }
    void LodeDict()
    {
        std::cout << "LodeDict" << std::endl;
        for(auto& line : _lines)
        {
            int pos = line.find(" ");
            std::cout << pos << std::endl;
            if(pos == std::string::npos) 
                continue;
            else
            {
                std::cout <<line.substr(0, pos) << "###" << line.substr(pos) << std::endl;
                _dict[line.substr(0, pos)] = line.substr(pos); //跳不跳过当前空格无所谓
                // std::string word = line.substr(0, pos);
                // std::string chinese = line.substr(pos);
                // _dict.insert(std::make_pair(word, chinese));
            }
        }
    }
    void LodeLines()
    {
        std::ifstream in(_dict_path);
        std::string line;
        while(std::getline(in, line))
        {
            std::cout << line << std::endl;
            _lines.push_back(line);
        }
        in.close();
    }
    std::string Excute(const std::string& word)
    {
        if(_dict.count(word))
            return _dict[word];
        else
            return "not find";
    }
private:
    std::string _dict_path;
    std::unordered_map<std::string, std::string> _dict;
    std::vector<std::string> _lines;
};